package com.java7;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;

/**
 * @Description TODO
 * @Author zhouhai
 * @Date2018/9/711:05
 **/
public class ForkJoinDemo {

    public static void main(String[] args) {
        //并行: 多核心参与
        //并发:一同参与
        //ForkJoin 线程池:ForkJoinPool
        System.out.printf("当前公用ForkJoin 线程池 并行数:%d\n", ForkJoinPool.commonPool().getParallelism());
        System.out.printf("当前CPU处理器数:%d\n", Runtime.getRuntime().availableProcessors());
        //与ThreadPoolExecutor类似
        ForkJoinPool forkJoinPool = new ForkJoinPool();

        forkJoinPool.invoke(new RecursiveAction() {
            @Override
            protected void compute() {
                System.out.printf("[Threade : %s]Hello,World ... \n",Thread.currentThread().getName());
            }
        });

        forkJoinPool.shutdown();
    }
}
